<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	
	String type = request.getParameter("type");
	String categoryId = request.getParameter("categoryId");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>新增商品分类</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/head.jsp"></jsp:include>
	<script type="text/javascript">
		var type = "<%=type%>";
		var categoryId = "<%=categoryId%>";
		
		$(document).ready(function(){
		});
		
		function save(){
			if($('#fm').form('validate')){
				var data = "&categoryId="+categoryId;
				data += "&name="+escape(escape($('#name').val()));
				data += "&url="+escape(escape($('#url').val()));
				data += "&description="+escape(escape($('#description').val()));
				data += "&sendMsg="+escape(escape($('#sendMsg').val()));
				data += "&layerOrder="+escape(escape($('#layerOrder').val()));
				data += "&pCount="+escape(escape($('#pCount').val()));
				
				var url =  path;
				
				if(type == "add") {
					url += "/category/save.do?t="+new Date().getTime();
				}else {
					url += "/category/update.do?t="+new Date().getTime();
				}
				
				$.ajax({
				  url: url,
				  data:data,
				  success: function(data) {
					   if(data == "1")
					   {
						   alertBox("操作成功！");
						   window.location = path+"/category/categoryMgr.do";
					   } else {
							alertBox("操作失败！");
					   }
				  }
				});
				
			}
		}
		
		function callback(){
			window.location = path+"/category/categoryMgr.do";
		}
	</script>
  </head>
  
  <body>
   <div class="right">
	<h1><b>${type=='add'?'新增商品分类':'编辑商品分类' }</b><span><img src="<%=basePath%>images/right_h1bg2.jpg" width="3" height="29" /></span></h1>
	<form id="fm">
	<div class="ri_main">
		<table width="97%" border="0" cellspacing="1" cellpadding="8" style="background:#d9d9d9;">
		  <tr>
		    <td width="21%" align="right" bgcolor="#FFFFFF">名称：</td>
		    <td width="79%" bgcolor="#FFFFFF">
		      <input id="name" name="name" class="easyui-validatebox" required="true" style="width:200px;" value="${category != null?category.name:''}">
		    </td>
		  </tr>
		  <tr>
		    <td width="21%" align="right" bgcolor="#FFFFFF">路径：</td>
		    <td width="79%" bgcolor="#FFFFFF">
		      <input id="url" name="url" class="easyui-validatebox" style="width:200px;" value="${category != null?category.url:''}">
		    </td>
		  </tr>
		  <tr>
		    <td width="21%" align="right" bgcolor="#FFFFFF">是否发送购物信息：</td>
		    <td width="79%" bgcolor="#FFFFFF">
		    	<select id="sendMsg" name="sendMsg">
					<c:forEach var="dict" items="${sendMsg}">
		    			<c:choose>
		    				<c:when test="${category != null && dict.code == category.sendMsg}">
	    						<option value="${dict.code}" selected="selected">${dict.name}</option>
		    				</c:when>
		    				<c:otherwise>
		    					<option value="${dict.code}">${dict.name}</option>
		    				</c:otherwise>
		    			</c:choose>
		    		</c:forEach>
				</select>
		      	<!-- <input id="sendMsg" name="sendMsg" class="easyui-validatebox" style="width:200px;" value="${category != null?category.sendMsg:''}"> -->
		    </td>
		  </tr>
		  <tr>
		    <td width="21%" align="right" bgcolor="#FFFFFF">排序编号：</td>
		    <td width="79%" bgcolor="#FFFFFF">
		      <input id="layerOrder" name="layerOrder" class="easyui-validatebox" style="width:200px;" value="${category != null?category.layerOrder:''}">
		    </td>
		  </tr>
		  <tr>
		    <td width="21%" align="right" bgcolor="#FFFFFF">购买数量：</td>
		    <td width="79%" bgcolor="#FFFFFF">
		      <input id="pCount" name="pCount" class="easyui-numberbox" style="width:200px;" value="${category != null?category.pcount:''}">
		    </td>
		  </tr>
		  <tr>
		    <td width="21%" align="right" bgcolor="#FFFFFF">描述：</td>
		    <td width="79%" bgcolor="#FFFFFF">
		    	<textarea id="description" name="description" rows="10" style="width: 400px">${category != null?category.description:''}</textarea>
		      	<!-- <input id="description" name="description" class="easyui-validatebox" style="width:200px;" value="${category != null?category.description:''}"> -->
		    </td>
		  </tr>
		  
		   
		   <tr>
		    <td align="center" bgcolor="#FFFFFF" colspan="2">
				<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">保存</a>
				<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-undo" onclick="callback()">取消</a>
			</td>
		   </tr>
		</table>
	</div>
	</form>
	</div>
  </body>
</html>
